package com.xzc.seckill.config;

import com.xzc.seckill.pojo.User;

/**
 * @author 徐生
 * @version 1.0
 * Date 2024/4/10 15:20
 * Description: 通过ThreadLocal获取user
 */
public class UserContext {
    //每个线程都有自己的ThreadLocal本地变量，把共享数据存放在这里，保证线程安全
    private static ThreadLocal<User> userHolder = new ThreadLocal<>();

    public static void setUser(User user){
        userHolder.set(user);
    }

    public static User getUser(){
        return userHolder.get();
    }
}
